package com.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;
import com.dao.RecruitDetailDao;
import com.opensymphony.xwork2.ActionContext;
import com.po.RecruitDetailInfoPO;
@Controller
public class RecruitDetailAction {
	@Autowired
	private RecruitDetailDao recruitDetailDao;
	private RecruitDetailInfoPO recruitDetailInfoPO;
	/**
	 * 展示详细的招聘信息
	 */
	public String show(){
		HttpServletRequest request = ServletActionContext.getRequest(); 
		String id = request.getParameter("id");
		recruitDetailInfoPO = recruitDetailDao.findRecruitDetailInfoById(id);
		
		return "show";
	}
	/**
	 * 修改时回显查找数据
	 * @return
	 */
	public String preUpdate(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = request.getParameter("id");
		ActionContext.getContext().put("id", id);
		recruitDetailInfoPO = recruitDetailDao.findRecruitDetailInfoById(id);
		return "preUpdate";
	}
	
	/**
	 * 修改详细的招聘信息
	 * @return
	 */
	public String update(){
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		Map<String, String> map = new HashMap<String, String>();
		int id = Integer.parseInt(request.getParameter("id"));
		recruitDetailInfoPO.setId(id);
		try {
			recruitDetailDao.updateDetailInfo(recruitDetailInfoPO);
			map.put("code", "EC001");
		} catch (Exception e) {
			map.put("code", "EC002");
		}
		try {
			String msg = JSON.toJSONString(map);
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().write(msg);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	
	
	
	
	public RecruitDetailInfoPO getRecruitDetailInfoPO() {
		return recruitDetailInfoPO;
	}
	public void setRecruitDetailInfoPO(RecruitDetailInfoPO recruitDetailInfoPO) {
		this.recruitDetailInfoPO = recruitDetailInfoPO;
	}
	
	
}
